package com.xxx.video.dynamic.presenters;

import android.content.Context;

import androidx.annotation.NonNull;

import com.xxx.video.commen.beans.BaseBean;
import com.xxx.video.commen.presenters.BasePresenter;
import com.xxx.video.commen.utils.ResponseUtils;
import com.xxx.video.commen.views.AddFriendExtraMessageDialog;
import com.xxx.video.dynamic.beans.PersonInfoBean;
import com.xxx.video.network.listeners.CommonResponseListener;
import com.xxx.video.network.utils.NetWorkUtils;

public class PersonInfoPresenter extends BasePresenter<IPersonInfoView> {

    public PersonInfoPresenter(@NonNull Context context, IPersonInfoView baseView) {
        super(context, baseView);
    }

    public void getFriendsInfo(String userId) {
        NetWorkUtils.getInstance().getFriendsInfo(userId, new CommonResponseListener<PersonInfoBean>() {

            @Override
            public void onSuccess(PersonInfoBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initData2View(successOb);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
                if (getBaseView() != null) {
                    getBaseView().showRootLayoutStatus(3);
                }
            }
        });
    }

    public void addFriends(PersonInfoBean.UserBean user) {
        AddFriendExtraMessageDialog addFriendExtraMessageDialog = new AddFriendExtraMessageDialog(context);
        addFriendExtraMessageDialog.show();
        addFriendExtraMessageDialog.setOnButtonClickListener(message -> NetWorkUtils.getInstance().addFriends(user.userId, user.username, user.nickName, user.picUrl, message, new CommonResponseListener<BaseBean>() {

            @Override
            public void onSuccess(BaseBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().addFriendSuccess();
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {

            }
        }));
    }
}
